#!/bin/sh -eu

# Slackware build script for bashdb
# Written by Erik Hanson  erik@slackbuilds.org

# This will build without readarray support. Read the INSTALL file in the
# source directory for instructions if you wish to enable readarray support.
# readarray speeds up initial loading of large scripts.

PRGNAM=bashdb
VERSION=4.0-0.1
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

PKG_VER=$(echo $VERSION | tr '-' '_')

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# Hack configure, upstream has "tested on bash 3.1 and 4.0 alpha"
sed -i "s/'4.0'|'3.2')/'4.0'|'3.2'|'3.1')/" configure

./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=/usr/man \
  --infodir=/usr/info

make
make install-strip DESTDIR=$PKG

find $PKG/usr/man/man1 -type f -exec gzip -9 {} \;
gzip -9 $PKG/usr/info/*.info
rm -rf $PKG/usr/info/dir

mkdir -p $PKG/usr/doc/$PRGNAM-$PKG_VER
cp -a AUTHORS COPYING ChangeLog ChangeLog.0 INSTALL NEWS README THANKS TODO \
  $PKG/usr/doc/$PRGNAM-$PKG_VER
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$PKG_VER/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$PKG_VER-$ARCH-$BUILD$TAG.tgz
